{include file="public/meta" /}
<title>新增产品 - 产品管理</title>

<body>
    <article class="page-container">
        <form class="form form-horizontal" id="form-goods-add">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品标题：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="输入产品标题" id="title" name="title">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品编号：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="goods_no" name="goods_no">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品分类：</label>
                <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="category_id" id="category_id" class="select">
					<option value="0">请选择产品分类</option>
					{volist name="categoryList" id="val"}
					<option value="{$val['id']}">{$val['title']}</option>
					{/volist}
				</select>
				</span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>封面图：</label>
                <div class="formControls col-xs-8 col-sm-9"> <span class="btn-upload form-group">
				<input class="input-text upload-url" type="text" name="img_url" id="img_url" nullmsg="请添加图片" style="width:400px">
				<a href="javascript:void(0);" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont">&#xe642;</i> 封面图</a>
				<input type="file" name="file-1" class="input-file" id="img-url-file">
				</span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>图片集：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <div class="uploadbtn">
                        <a id="btn"></a>
                    </div>
                    <ul id="ul_pics" class="ul_pics clearfix"></ul>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>销售价格：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="0.00" placeholder="" id="sell_price" name="sell_price">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>市场价格：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="0.00" placeholder="" id="market_price" name="market_price">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>商品库存：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="0" placeholder="" id="stock" name="stock">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>显示状态：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="radio" class="sorting_disabled" value="0" name="status" checked>上架
                    <input type="radio" class="sorting_disabled" value="1" name="status">下架
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>推荐类型：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="checkbox" class="sorting_disabled" value="1" placeholder="" id="is_rec" name="is_rec">推荐
                    <input type="checkbox" class="sorting_disabled" value="1" placeholder="" id="is_top" name="is_top">置顶
                    <input type="checkbox" value="1" id="is_special" name="is_special">特价秒杀
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>排序：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="0" placeholder="" id="sort" name="sort">
                </div>
            </div>
            <!-- <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>一级：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="first" name="first">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>二级：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="second" name="second">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>三级：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="third" name="third">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>二次购买：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="again" name="again">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>二次购买一级：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="again_first" name="again_first">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>二次购买二级：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="again_second" name="again_second">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>二次购买三级：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="again_third" name="again_third">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>购买所得积分：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="buy_point" name="buy_point">
            </div>
        </div> -->
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">商品描述：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <textarea id="content" name="content" style="width:100%;height:400px;"></textarea>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                    <button onClick="goods_add();" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存提交</button>
                    <button onClick="removeIframe();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                </div>
            </div>
        </form>

    </article>

    <!--_footer 作为公共模版分离出去-->
    {include file="public/footer" /}
    <!--/_footer /作为公共模版分离出去-->

    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script>
    <script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js">
    </script>
    <script type="text/javascript" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
    <script src="__LIB__/plupload.full.min.js"></script>

    <script type="text/javascript">
        //创建实例的构造方法
        var uploader = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight,html4',
            browse_button: 'btn',
            url: "{:url('Common/upload')}",
            flash_swf_url: 'plupload/Moxie.swf',
            silverlight_xap_url: 'plupload/Moxie.xap',
            filters: {
                max_file_size: '2mb', //最大上传文件大小（格式100b, 10kb, 10mb, 1gb）
                mime_types: [ //允许文件上传类型
                    {
                        title: "files",
                        extensions: "jpg,png,gif"
                    }
                ]
            },
            multi_selection: true, //true:ctrl多文件上传, false 单文件上传
            init: {
                FilesAdded: function(up, files) { //文件上传前
                    if ($("#ul_pics").children("li").length > 30) {
                        alert("您上传的图片太多了！");
                        uploader.destroy();
                    } else {
                        var li = '';
                        plupload.each(files, function(file) { //遍历文件
                            li += "<li id='" + file['id'] + "'><div class='progress'><span class='bar'></span><span class='percent'>0%</span></div></li>";
                        });
                        $("#ul_pics").append(li);
                        uploader.start();
                    }
                },
                UploadProgress: function(up, file) { //上传中，显示进度条
                    $("#" + file.id).find('.bar').css({
                        "width": file.percent + "%"
                    }).find(".percent").text(file.percent + "%");
                },
                FileUploaded: function(up, file, info) { //文件上传成功的时候触发
                    var data = JSON.parse(info.response);
                    $("#" + file.id).html("<div class='upimg_box'> <img src='" +
                        data.data + "'/><div class='sctxt'><a href='javascript:void(0);' bindImageUrl='" +
                        data.data + "' onclick='test(this)'>删除</a></div><input type='hidden' name='images[]' value=" +
                        data.data + "></div>");

                },
                Error: function(up, err) { //上传出错的时候触发
                    alert(err.message);
                }
            }
        });
        uploader.init();

        function test(obj) {
            var bindImageUrl = $(obj).attr('bindImageUrl');
            $(obj).parent().parent().css('display', 'none')
            $(obj).parent().next().removeAttr('name');
            $.post(
                "{:url('Common/imageDel')}", {
                    'imageUrl': bindImageUrl
                },
                function(data) {
                    if (data != 1) {
                        layer.msg('删除失败');
                    }
                }, 'json'
            );
        }
    </script>
    <script type="text/javascript">
        $(function() {
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            var ue = UE.getEditor('content');

        });
        //单图片上传
        $('#img-url-file').change(function() {
            var filess = $('#img-url-file')[0].files[0]
            console.log(filess);
            var fm = new FormData();
            fm.append('image', filess);

            $.ajax({
                type: 'post',
                url: "{:url('Common/uploadImage')}",
                data: fm,
                processData: false,
                contentType: false,
                success: function(data) {
                    //alert(data);
                    var jdata = JSON.parse(data);
                    if (jdata.code == 0) {
                        parent.layer.msg(jdata.msg, {
                            icon: 6,
                            time: 1000
                        });
                        var imgurl = jdata.data;
                        imgurl = imgurl.replace(/\\/g, "/");
                        $('#img_url').val(imgurl);
                    } else {
                        parent.layer.msg(jdata.msg, {
                            icon: 5,
                            time: 1000
                        });
                    }

                },
                error: function(data) {
                    layer.msg('500系统错误，请重试！', {
                        icon: 5,
                        time: 1000
                    });
                }
            });
        });

        function goods_add() {
            /*var cid=parseInt($('#category_id').val());
            if(cid==0) {
                alert('请选择产品分类');
                return false;
            }*/
            /*{
                    'title':$('#title').val(),
                    'goods_no': $("#goods_no").val(),
                    'category_id': $("#category_id").val(),
                    'img_url': $("#img_url").val(),
                    'images': $("#images").val(),
                    'sell_price': $("#sell_price").val(),
                    'market_price': $("#market_price").val(),
                    'stock': $("#stock").val(),
                    'status': $("#status").val(),
                    'is_rec': $("#is_rec").val(),
                    'is_top': $("#is_top").val(),
                    'is_special': $("#is_special").val(),
                    'sort': $("#sort").val(),
                    'first_level': $("#first_level").val(),
                    'second_level':$('#second_level').val(),
                    'third_level':$('#third_level').val(),
                    'content':content
                }*/
            // var content=UE.getEditor('content').getContent();
            var form = $("#form-goods-add").serializeArray();
            $.ajax({
                url: "{:url('Goods/add')}",
                type: "post",
                data: form,
                dataType: "json",
                success: function(data) {
                    if (data.code == 0) {
                        parent.layer.msg(data.msg, {
                            icon: 6,
                            time: 1000
                        });
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.window.location.reload();
                        parent.layer.close(index);
                    } else {
                        parent.layer.msg(data.msg, {
                            icon: 5,
                            time: 1000
                        });
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }
                },
                error: function(data) {
                    layer.msg('500系统错误，请联系管理员！', {
                        icon: 5,
                        time: 1000
                    });
                }
            });
        }
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
</body>
</head>

</html>